<%@ page language="java" pageEncoding="utf-8"%>
<%@ page import="com.witframework.web.mvc.WebContext"%>
<%@ include file="/WEB-INF/classes/com/witframework/webroot/framework/common/taglibs.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
	<meta http-equiv = "pragma" content = "no-cache" />
<%@ include	file="/WEB-INF/classes/com/witframework/webroot/framework/common/meta.jsp"%>
<%@ include	file="/WEB-INF/classes/com/witframework/webroot/framework/common/css.jsp"%>
<%@ include	file="/WEB-INF/classes/com/witframework/webroot/framework/common/componentsmeta.jsp"%>
<%
	WebContext webContext = new WebContext(request, response);
	String treeid = webContext.getParameterAndsetAttribute("treeid");
	String root = webContext.getParameterAndsetAttribute("root");
	//指向父节点的属性名称
	String parent = webContext.getParameterAndsetAttribute("parentid");

	String multiple = webContext.getParameterAndsetAttribute("multiple");
	multiple = (multiple == null ? "false" : multiple);
	int isradio = (multiple.equalsIgnoreCase("true") || multiple.equalsIgnoreCase("1")) ? 0 : 1;

	//默认的选中项
	String selected = webContext.getParameterAndsetAttribute("selected");

	String childrenData = "/customSelectTreeController.wit?" + request.getQueryString();

	String dialogHeight = webContext.getParameterAndsetAttribute("height");
	int height = (dialogHeight == null ? 450 : Integer.parseInt(dialogHeight));
	String dialogWidth = webContext.getParameterAndsetAttribute("width");
	int width = (dialogWidth == null ? 618 : Integer.parseInt(dialogWidth));
%>
<script>
isradio=<%=isradio%>;
function selectit(){	
	var p1="",p2="",p3="";	
	var selectedItems=tree.getAllChecked();	
	if(selectedItems.length<1){
		alert("请选择至少一项！");
		return;
	}
	var items=selectedItems.split(",");
	for(i=0;i<items.length;i++){
		p1=p1+items[i]+",";		
		p2=p2+tree.getItemText(items[i])+",";		
		u=tree.getUserData(items[i],"others");			
		if(typeof u=='string')
			p3=p3+u+",";
		
	}	
	closeSelectWinAndSet('${treeid}',p1.substring(0,p1.length-1),p2.substring(0,p2.length-1),p3.substring(0,p3.length-1));	
}

var tree;
function loadtree(){	
	if(window.navigator.userAgent.indexOf("IE 6.0") >= 0)
		tree=new dhtmlXTreeObject("treebox2","<%=width - 55%>","<%=height - 130%>","<%=root%>");			
	else if(window.navigator.userAgent.indexOf("Opera")>=0)
		tree=new dhtmlXTreeObject("treebox2","<%=width - 38%>px","<%=height - 90%>px","<%=root%>");
	else
		tree=new dhtmlXTreeObject("treebox2","<%=width - 38%>px","<%=height - 110%>px","<%=root%>");
	tree.setImagePath("${contextPath}/webresource/components/tree/imgs/csh_winstyle/");
	tree.enableSmartXMLParsing(0);
	tree.enableSmartCheckboxes(0);
	tree.enableHighlighting(1);  
	tree.enableCheckBoxes(1,1);
	tree.enableRadioButtons(<%=isradio%>);			
	tree.enableAutoTooltips(1);
	tree.enableThreeStateCheckboxes(0);
	tree.enableFixedMode(1);
	//tree.enableTreeImages(0);
	tree.enableMultiLineItems(0);
	tree.setXMLAutoLoading("${contextPath}<%=childrenData%>");
	tree.loadXML("${contextPath}<%=childrenData%>&id=<%=root%>");
	tree.setOnCheckHandler(check);
}
function find(label){
	id=tree.findItem(label);
}
function check(id,state){		
	if(isradio==1){		
		var selectedItems=tree.getAllChecked();		
		var items=selectedItems.split(",");
		for(i=0;i<items.length;i++){
			tree.setCheck(items[i],0);
		}
		tree.setCheck(id,state);
	}
}
</script>
</head>
<body onload="loadtree();document.getElementById('itemlabel').focus();" id="treebox" >	
		<table width="95%">
			<tr>
				<td align=left class="operation">
					<div class="filter">
					<input id="itemlabel" size=10/>
					<a href="#" onclick="find(document.getElementById('itemlabel').value);" accesskey="f">
						<img src="${contextPath}/webresource/images/ico_btn_search.gif">
						查询(F)
					</a>
					
					<a href="#" onclick="tree.refreshItem()" accesskey="r">
						<img src="${contextPath}/webresource/images/meta/refresh.png">						
					</a>
					</div>
				</td>
				<td align=right class="operation">					
					<a id="ok" href="#" onclick="selectit();" accesskey="a">
						<img src="${contextPath}/webresource/images/meta/ok.gif">
						确定(S)
					</a>
					<a href="#" onclick="closeSelectWinAndClear('${treeid}')" accesskey="c">
						<img src="${contextPath}/webresource/images/meta/clear.gif">
						清除(C)
					</a>
				</td>
			</tr>	
			<tr><td colspan=2>
				<div id="treebox2" style="width:<%=width - 48%>px;height:<%=height - 130%>px;">
				</div>	
			</td>			
		</table>			
			
</body>
</html>